package com.wh1200.mybatis.xmlless.resolver

import com.wh1200.mybatis.xmlless.config.BaseResolverTest
import com.wh1200.xmlless.test.dao.TestModelDAO
import com.wh1200.xmlless.test.model.TestModel
import org.junit.jupiter.api.Test
import kotlin.reflect.jvm.javaMethod
import kotlin.test.assertContains
import kotlin.test.assertNotNull

/**
 *
 * @author wuhao
 * @date 2024/1/22 19:37
 * @since v0.0.0
 * @version 1.0
 */
class TestModelDAOResolver : BaseResolverTest(
    TestModelDAO::class.java
) {

  @Test
  fun resolveInsert() {
    val method = TestModelDAO::insert.javaMethod!!
    val query = createQueryForMethod(method)
    assertNotNull(query.sql)
  }

  @Test
  fun resolveUpdate() {
    val method = TestModelDAO::update.javaMethod!!
    val update = createQueryForMethod(method)
    val sql = update.sql
    assertNotNull(sql)
    assertContains(
        sql, "<if test=\"updateNotEmpty.size() &gt; 0\">"
    )
    assertContains(
        sql, "<if test=\"updateNotNull != null\">"
    )
    assert(!sql.contains("test=\"updateAlways"))
    println(update.sql)
  }

  @Test
  fun resolveSaveOrUpdate() {
    val method = TestModelDAO::saveOrUpdate.javaMethod!!
    val update = createQueryForMethod(method)
    val sql = update.sql
    assertNotNull(sql)
    assertContains(sql, "update_always = #{updateAlways}")
    assert(!sql.contains("update_never = "))
  }

}
